import type { ChannelList } from '../../types/data'
import type { ChannelAction } from '../../types/store'

type Channels = {
  channels: ChannelList
  activeId: number
}

// 默认值
const initalState: Channels = {
  channels: [],
  activeId: 0,
}
// 执行分发事件
export const channels = (
  state = initalState,
  action: ChannelAction
): Channels => {
  switch (action.type) {
    // 获取频道列表数据
    case 'channel/get':
      return {
        ...state,
        channels: action.payload,
      }

    // 切换高亮
    case 'channel/toggle':
      return {
        ...state,
        activeId: action.payload,
      }

    default:
      return state
  }
}
